package cz.muni.fi.pa165.travelagency.services;

import cz.muni.fi.pa165.travelagency.dto.TourDTO;
import cz.muni.fi.pa165.travelagency.entities.Tour;
import cz.muni.fi.pa165.travelagency.persistence.ITourDAO;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Tour service implementation
 *
 * @author Petr Stribny
 * @created 02-11-2012
 * @version 1.0
 */
@Service
@Transactional
public class TourService implements ITourService {

    private Mapper mapper;
    private ITourDAO tourDAO;
    
    @Autowired
    void setTourDao(ITourDAO tourDAO)
    {
        this.tourDAO = tourDAO;
    }

    @Autowired
    public void setMapper(Mapper mapper) {
        this.mapper = mapper;
    }
    
    @Override
    public void createTour(TourDTO tour) {
        tourDAO.createTour(mapper.map(tour, Tour.class));
    }

    @Override
    public void deleteTour(TourDTO tour) {
        tourDAO.deleteTour(mapper.map(tour, Tour.class));
    }

    @Override
    public TourDTO getTour(Long id) {
        Tour t = tourDAO.getTour(id);
        return t == null ? null : mapper.map(t, TourDTO.class);
    }

    @Override
    public void updateTour(TourDTO tour) {
        tourDAO.updateTour(mapper.map(tour, Tour.class));
    }
}
